package org.gpp.proj1.robot.action;

import java.util.LinkedList;

import junit.framework.TestCase;

import org.gpp.proj1.robot.action.step.ActionStep;

public class ActionCacheTest extends TestCase {
	
	public void tearDown() {
		ActionCache.getInstance().clear();
	}

	/*
	 * Test method for 'org.gpp.proj1.robot.action.ActionCache.getAction(String)'
	 */
	public void testGetAction() {
		// Cannot get action with null name
		try {
			ActionCache.getInstance().getAction( null );
			fail();
		} catch (AssertionError e) {
			// expected error
		}
		
		// Action "action" must not exist
		assertNull( ActionCache.getInstance().getAction("action" ) );
		
		ActionCache.getInstance().addAction( new PartAction( "action", new LinkedList<ActionStep>() ) );
		
		// Valid construct
		try {
			assertNotNull( ActionCache.getInstance().getAction( "action" ) );
		} catch (AssertionError e) {
			fail();
		}
	}

	/*
	 * Test method for 'org.gpp.proj1.robot.action.ActionCache.addAction(PartAction)'
	 */
	public void testAddAction() {
		// Action "action" must not exist
		assertNull( ActionCache.getInstance().getAction("action" ) );
		
		ActionCache.getInstance().addAction( new PartAction( "action", new LinkedList<ActionStep>() ) );
		
		// Action "action" must exist
		assertNotNull( ActionCache.getInstance().getAction("action" ) );
	}

	/*
	 * Test method for 'org.gpp.proj1.robot.action.ActionCache.clear()'
	 */
	public void testClear() {
		// Action "action" must not exist
		assertNull( ActionCache.getInstance().getAction("action" ) );
		
		ActionCache.getInstance().addAction( new PartAction( "action", new LinkedList<ActionStep>() ) );
		
		// Action "action" must exist
		assertNotNull( ActionCache.getInstance().getAction("action" ) );
		
		ActionCache.getInstance().clear();
		
		// Action "action" must not exist
		assertNull( ActionCache.getInstance().getAction("action" ) );
	}
}
